﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace HobSoft.SoccerBet2014.Domain.Models
{
    using Core;
    [Serializable]
    [DataContract]
    public class OddsPrice : IModel
    {
        private OddsPrice()
        {
            Price = 0m;
            Type = OddsPriceType.Home;
        }

        public OddsPrice(decimal price, OddsPriceType type)
        {
            Price = price;
            Type = type;
        }

        private byte _bmId;
        [Key]
        [Required]
        [DataMember(IsRequired = true)]
        public byte BmID
        {
            get
            {
                if (_odds != null && _odds.BmID != _bmId)
                    _bmId = _odds.BmID;
                return _bmId;
            }
            set { _bmId = value; }
        }

        private string _oddsId;
        [Key]
        [Required]
        [DataMember(IsRequired = true)]
        [MaxLength(50)]
        [MinLength(1)]
        public string OddsID
        {
            get
            {
                if (_odds != null && _odds.OddsID != _oddsId)
                    _oddsId = _odds.OddsID;
                return _oddsId;
            }
            set { _oddsId = value; }
        }

        private Odds.MarketType _mType;
        [Required]
        [DataMember(IsRequired = true)]
        public Odds.MarketType MkType
        {
            get
            {
                if (Odds != null && _mType != Odds.Type)
                    _mType = Odds.Type;
                return _mType;
            }
            set { _mType = value; }
        }

        private decimal _price;
        [DataMember()]
        public decimal Price
        {
            get { return _price; }
            set { _price = value; }
        }

        private OddsPriceType _type;
        [Key]
        [Required]
        [DataMember(IsRequired = true)]
        public OddsPriceType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        private Odds _odds;
        [IgnoreDataMember()]
        public Odds Odds
        {
            get
            {
                return _odds;
            }
            set
            {
                _odds = value;
            }
        }

        public enum OddsPriceType : byte
        {
            Home,
            Away,
            Tie,
            Under,
            Over
        }
    }
}
